- 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
1,194
Solved
13 Replies

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
Glitch8
 ( 11.82% )
- 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
Glitch8
 ( 11.82% )
- 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
Glitch8
 ( 11.82% )
- ago
#8
I just copied and pasted the code above exactly as is.
1
- ago
#9
Update: code in Post #1 above won't work anymore since Morningstar stopped returning the float data for stocks.
0
- ago
#10
Are there any chances to bring the "Shares" or perhaps as "Float" back? Maybe from another provider? I and other traders like to use this condition for stock screening. Thanks.
0
- ago
#11
Re: shares.
1) A new provider suite is in the works for quality subscription-based data, with an event provider returning common shares outstanding. (Despite they offer dozens of fundamental items, Float isn't one of them).
2) Likewise, IQFeed has common shares outstanding.
3) Finally, YCharts (free event provider) may be used to get shares.

Getting Float back would take having a reliable source of data. Do you have any suggestions?
0
- ago
#12
I use Finviz.com. Usually I do a stock screen then save the list as a portfolio and import it to WL8. It is a bit of work but it does the job. Not sure if their info can be imported to WL directly as an extension. It would be nice. Thank you.

https://finviz.com/screener.ashx?v=111&f=sh_float_o5
0
- ago
#13
Finviz looks like stable and robust source. Thus, for B30 I'm working on getting Float back. So for what concerns Float, the code in Post #1 should start working again seamlessly then.
0

Reply

Bookmark

Sort