-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
885 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace ProjectX.Core.Strategy; | ||
|
||
public record StrategyChartData(string time, double amount, double amountHold); |
46 changes: 46 additions & 0 deletions
46
ProjectX.GatewayAPI/Controllers/BacktestServiceController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.OpenApi.Any; | ||
using Newtonsoft.Json; | ||
using ProjectX.Core.Services; | ||
using ProjectX.Core.Strategy; | ||
using static System.Runtime.InteropServices.JavaScript.JSType; | ||
|
||
namespace ProjectX.GatewayAPI.Controllers; | ||
|
||
[ApiController] | ||
[Route("[controller]")] | ||
public class BacktestServiceController | ||
{ | ||
private readonly ILogger<BacktestServiceController> _logger; | ||
private readonly IStockSignalService _stockSignalService; | ||
private readonly IBacktestService _backtestService; | ||
|
||
public BacktestServiceController(ILogger<BacktestServiceController> logger, IStockSignalService stockSignalService, IBacktestService backtestService) | ||
{ | ||
this._logger = logger; | ||
this._stockSignalService = stockSignalService; | ||
this._backtestService = backtestService; | ||
} | ||
|
||
[HttpGet] | ||
public string Get() | ||
{ | ||
return "Hello from BacktestServiceController"; | ||
} | ||
|
||
[HttpGet("LongShortStrategy")] | ||
public async Task<IEnumerable<StrategyChartData>> Get(string ticker, DateTime fromDate, DateTime toDate, double notional) | ||
{ | ||
int movingWindow = 10; | ||
double signalIn = 0.5; | ||
double signalOut = 0.4; | ||
|
||
bool isReinvest = false; | ||
MovingAverageImpl movingAverageImpl = MovingAverageImpl.BollingerBandsImpl; | ||
|
||
var smoothenedSignals = await _stockSignalService.GetSignalUsingMovingAverageByDefault(ticker, fromDate, toDate, movingWindow, movingAverageImpl); | ||
List<StrategyPnl> pnls = _backtestService.ComputeLongShortPnl(smoothenedSignals, notional, signalIn, signalOut, new TradingStrategy(TradingStrategyType.MeanReversion, isReinvest)).ToList(); | ||
var data = pnls.Select(p => new StrategyChartData(p.Date.ToString("ddMMyy"), p.PnLCum, p.PnLCumHold)); | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.