Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ooples committed Feb 19, 2022
2 parents 8bb9d24 + c952e19 commit dbaba4d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions Interfaces/IStockData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface IStockData
List<decimal> LowPrices { get; }
List<decimal> ClosePrices { get; }
List<decimal> Volumes { get; }
List<DateTime> Dates { get; }
List<decimal> CustomValuesList { get; }
Dictionary<string, List<decimal>> OutputValues { get; }
List<Signal> SignalsList { get; }
Expand Down
4 changes: 3 additions & 1 deletion Models/StockData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ public class StockData : IStockData
public List<decimal> LowPrices { get; set; }
public List<decimal> ClosePrices { get; set; }
public List<decimal> Volumes { get; set; }
public List<DateTime> Dates { get; set; }
public List<decimal> CustomValuesList { get; set; }
public Dictionary<string, List<decimal>> OutputValues { get; set; }
public List<Signal> SignalsList { get; set; }
public int Count { get; set; }

public StockData(IEnumerable<decimal> openPrices, IEnumerable<decimal> highPrices, IEnumerable<decimal> lowPrices, IEnumerable<decimal> closePrices,
IEnumerable<decimal> volumes)
IEnumerable<decimal> volumes, IEnumerable<DateTime> dates)
{
OpenPrices = new List<decimal>(openPrices);
HighPrices = new List<decimal>(highPrices);
LowPrices = new List<decimal>(lowPrices);
ClosePrices = new List<decimal>(closePrices);
Volumes = new List<decimal>(volumes);
Dates = new List<DateTime>(dates);
InputValues = new List<decimal>(closePrices);
CustomValuesList = new List<decimal>();
OutputValues = new Dictionary<string, List<decimal>>();
Expand Down
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@ using static OoplesFinance.StockIndicators.Calculations;
const string paperApiKey = "REPLACEME";
const string paperApiSecret = "REPLACEME";
const string symbol = "AAPL";
var secretKey = new SecretKey(paperApiKey, paperApiSecret);
var alpacaDataClient = Environments.Paper.GetAlpacaDataClient(secretKey);
var bars = (await alpacaDataClient.GetHistoricalBarsAsync(new HistoricalBarsRequest(symbol, new DateTime(2021, 1, 1),
new DateTime(2021, 12, 15), BarTimeFrame.Day)).ConfigureAwait(false)).Items.SelectMany(x => x.Value);
var startDate = new DateTime(2021, 01, 01);
var endDate = new DateTime(2021, 12, 31);

var closePrices = bars.Select(x => x.Close);
var openPrices = bars.Select(x => x.Open);
var highPrices = bars.Select(x => x.High);
var lowPrices = bars.Select(x => x.Low);
var volumes = bars.Select(x => x.Volume);
var client = Environments.Paper.GetAlpacaDataClient(new SecretKey(paperApiKey, paperApiSecret));
var bars = (await client.ListHistoricalBarsAsync(new HistoricalBarsRequest(symbol, startDate, endDate, BarTimeFrame.Day)).ConfigureAwait(false)).Items;
var stockData = new StockData(bars.Select(x => x.Open), bars.Select(x => x.High), bars.Select(x => x.Low), bars.Select(x => x.Close), bars.Select(x => x.Volume), bars.Select(x => x.TimeUtc));

var stockData = new StockData(openPrices, highPrices, lowPrices, closePrices, volumes);
var results = stockData.CalculateBollingerBands();
var upperBandList = results.OutputValues["UpperBand"];
var middleBandList = results.OutputValues["MiddleBand"];
var lowerBandList = results.OutputValues["LowerBand"];

```

### Support This Project
Expand Down

0 comments on commit dbaba4d

Please sign in to comment.