- ago
Is there an easy way to determine the available number of shares for each symbol in a dataset on a bar basis (similar to bars.Volume)?

I see the MorningStar Event provider has Shares as an option but the sample coding just shows how to display the header text via string.
0
442
Solved
9 Answers

Reply

Bookmark

Sort
- ago
#1
Float or number of shares isn't calculated but its last value (snapshot) can be obtained from external sources. Here is an undocumented method to get them in your WL7 strategy:

SymbolMetadataExtractor.GetMetadataForSymbol(symbol)

The class has the following properties:
CODE:
public string Sector public string Industry public string Description public string Exchange public long Float


Float is returned by the like-named property. Check out this quick example:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; using WealthLab.Data; namespace WealthScript1 { public class MyStrategy : UserStrategyBase { //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          var md = SymbolMetadataExtractor.GetMetadataForSymbol(bars.Symbol);          WriteToDebugLog(string.Format("Float of {0} is: {1}", bars.Symbol, md.Float.ToString())); } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below } }


QUOTE:
--AAPL--
Float of AAPL is: 16677840000
1
Best Answer
- ago
#2
QUOTE:
I see the MorningStar Event provider has Shares as an option but the sample coding just shows how to display the header text via string.

You can plot Shares with the help of Fundamental indicator. There's also a FundamentalRatio if you need to construct a ratio of a price/event.

Here's a quick example I whipped up to demonstrate usage of the Morningstar event provider. Make sure to check the Morningstar provider on the Event providers tab and its "Shares" item in "Select items to plot" nearby:

CODE:
using WealthLab.Backtest; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; namespace WealthScript1 {    public class MyStrategy1 : UserStrategyBase    {       Fundamental nrOfShares;              //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {          if (bars.EventDataPoints.Count > 0)          {             nrOfShares = new Fundamental(bars, "Shares", true);             PlotIndicator(nrOfShares);          }       }       //execute the strategy rules here, this is executed once for each bar in the backtest history       public override void Execute(BarHistory bars, int idx)       {       }    } }


Note the carryForward parameter which allows the single (annual) value of shares received from the source to be propagated forward.

1
- ago
#3
How can this value (integer) be brought into the execute loop? It returns 0 currently when trying the current above code.
0
- ago
#4
You’ll need to be sure you have an Event Provider enabled that can provide the desired fundamental data.
0
- ago
#5
MorningStar is enabled with 'Shares' enabled.
0
- ago
#6
The code Eugene posted is working for me when I run it on a stock like AAPL.
0
- ago
#7
@eralbanese

Not sure what you may be doing in the Execute method exactly, can you share code?
0
- ago
#8
I just copied and pasted the code above exactly as is.
1
- ago
#9
Update: code ni post #1 above won't work anymore since Morningstar stopped returning the float data for stocks.
0

Reply

Bookmark

Sort