Skip to content

Commit

Permalink
Bump
Browse files Browse the repository at this point in the history
  • Loading branch information
bleunguts committed Jan 29, 2024
1 parent 2fb3187 commit ce13638
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ProjectX.GatewayAPI/Controllers/BacktestServiceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,31 @@ public string Get()
public async Task<ActionResult<StrategyResults>> ComputeLongShortPnl(string ticker, DateTime fromDate, DateTime toDate, double notional, int movingWindow, double signalIn, double signalOut, MovingAverageImpl movingAverageImpl)
{
var strategy = new TradingStrategy(TradingStrategyType.MeanReversion, shouldReinvest: false);

var smoothenedSignals = await _stockSignalService.GetSignalUsingMovingAverageByDefault(ticker, fromDate, toDate, movingWindow, movingAverageImpl);
var strategyPnls = _backtestService.ComputeLongShortPnl(smoothenedSignals, notional, signalIn, signalOut, strategy);
var yearlyPnls = _backtestService.GetYearlyPnl(strategyPnls);
var drawdownPnls = _backtestService.CalculateDrawdown(strategyPnls, notional);

return Ok(new StrategyResults(strategyPnls, yearlyPnls, drawdownPnls));
}

[HttpGet("ComputeLongShortPnlMatrix")]
public async Task<ActionResult<IEnumerable<MatrixStrategyPnl>>> ComputeLongShortPnlMatrix(string ticker, DateTime fromDate, DateTime toDate, double notional)
{
var strategy = new TradingStrategy(TradingStrategyType.MeanReversion, shouldReinvest: false);

var marketPrices = await _stockMarketSource.GetPrices(ticker, fromDate, toDate);
var pnls = _backtestService.ComputeLongShortPnlFull(marketPrices, notional, strategy);
return Ok(pnls);
var matrixPnls = _backtestService.ComputeLongShortPnlFull(marketPrices, notional, strategy);

return Ok(matrixPnls);
}

[HttpGet("ComputeLongShortPnlStrategyChartData")]
public async Task<ActionResult<IEnumerable<StrategyChartData>>> ComputeLongShortPnlStrategyChartData(string ticker, DateTime fromDate, DateTime toDate, double notional, MovingAverageImpl movingAverageImpl = MovingAverageImpl.BollingerBandsImpl)
{
var strategy = new TradingStrategy(TradingStrategyType.MeanReversion, shouldReinvest: false);

try
{
var strategy = new TradingStrategy(TradingStrategyType.MeanReversion, shouldReinvest: false);

var marketPrices = await _stockMarketSource.GetPrices(ticker, fromDate, toDate);
var pnlRanking = _backtestService.ComputeLongShortPnlFull(marketPrices, notional, strategy);

Expand All @@ -73,6 +73,7 @@ public async Task<ActionResult<IEnumerable<StrategyChartData>>> ComputeLongShort
var smoothenedSignals = await _stockSignalService.GetSignalUsingMovingAverageByDefault(ticker, fromDate, toDate, movingWindow, movingAverageImpl);
List<StrategyPnl> pnlForMaximumProfit = _backtestService.ComputeLongShortPnl(smoothenedSignals, notional, signalIn, signalOut, strategy).ToList();
var data = pnlForMaximumProfit.Select(p => new StrategyChartData(p.Date.ToString("ddMMyy"), p.PnLCum, p.PnLCumHold));

return Ok(data);
}
catch(Exception e) when (e.Message.Contains("TooManyRequests"))
Expand Down

0 comments on commit ce13638

Please sign in to comment.