@run-out That's fair, thank you for the reply.
Best posts made by Void
-
RE: Swapping price and SMA data to match UK stock prices?
-
Swapping price and SMA data to match UK stock prices?
So quick bit of background...
The London Stock Exchange (LSE) prices are formatted like this : 129.02 for the stock Vodafone (ticker VOD on the LSE, and VOD.L on Yahoo Finance)
However, the actual price of a single share of Vodafone is £1.29 and not £129.02 as it is being read by backtrader as it is assuming it is dollars instead of UK pence.
The stock price is already exchanged to the UK price as it is using the LSE price so there is no exchange rate issues here.
Now we can fix the price format by taking the data.close[0] of our UK stock and dividing it by 100 to move the decimal place, which is okay and returns the correct amount now, e.g £1.29.
The problem now comes from using indicators like SMA which are still operating in effectively dollar amounts.
For example :
In the image above we can see that the price of the stock is 1.30 or £1.30 but the Fast and Slow SMA are reading 131.31 and 119.71 respectively.
My question is how would one go about potentially implementing a similar fix as discussed above to each SMA.
If that is not possible, then what would be the alternative to manipulating the SMA output so that it can effectively be used for UK price formatted stocks.
If you need any more information or clarification then don't hesitate to ask.
Latest posts made by Void
-
RE: Swapping price and SMA data to match UK stock prices?
@run-out That's fair, thank you for the reply.
-
RE: Swapping price and SMA data to match UK stock prices?
@run-out following on to my previous reply, if it isn't the best for live trading then that is okay, as I could replicate the live trading Strategies directly inside of MT5 with their scripting platform, i believe, correct?
And then MT5 could handle the actual algo trading? And backtrader could be solely for testing strategies in preparation for moving the best ones over to MT5? This would allow me to use your recommendation of yfinance for the problem in my original post and save me having to code the live trading aspect of backtrader as I'm semi-new to python which is a time saver.
But I would like the opinion of someone who knows their stuff!
-
RE: Swapping price and SMA data to match UK stock prices?
@run-out thanks for the input, that is really helpful.
I am just wondering if this is a viable option for live trading as this is the plan in the future? I did read up on it and they say there are obviously better paid APIs out there (which I can't really get involved with right now) if you are going down the full live trading route.
My main goal for the project is to build a solid base with backtrader and a handful of strategies coded that I can switch between US and UK price formats and then hopefully integrate Backtrader in to MT5 for actual trading.
Any advice on this please?
-
RE: Swapping price and SMA data to match UK stock prices?
class ShortSMA(backtrader.Strategy): params = (('fast', 20), ('slow',100 ), ('order_precentage', 0.95), ('ticker', 'VOD')) def __init__(self): self.fast_moving_average = backtrader.indicators.SMA( self.data.close, period = self.p.fast , plotname ='5 Day Moving Average' ) self.slow_moving_average = backtrader.indicators.SMA( self.data.close, period = self.p.slow, plotname ='19 Day Moving Average' ) self.crossover = backtrader.indicators.CrossOver(self.fast_moving_average, self.slow_moving_average)
Forgot to include a code snippet, as you can see it is just a simple SMA crossover strategy.
-
Swapping price and SMA data to match UK stock prices?
So quick bit of background...
The London Stock Exchange (LSE) prices are formatted like this : 129.02 for the stock Vodafone (ticker VOD on the LSE, and VOD.L on Yahoo Finance)
However, the actual price of a single share of Vodafone is £1.29 and not £129.02 as it is being read by backtrader as it is assuming it is dollars instead of UK pence.
The stock price is already exchanged to the UK price as it is using the LSE price so there is no exchange rate issues here.
Now we can fix the price format by taking the data.close[0] of our UK stock and dividing it by 100 to move the decimal place, which is okay and returns the correct amount now, e.g £1.29.
The problem now comes from using indicators like SMA which are still operating in effectively dollar amounts.
For example :
In the image above we can see that the price of the stock is 1.30 or £1.30 but the Fast and Slow SMA are reading 131.31 and 119.71 respectively.
My question is how would one go about potentially implementing a similar fix as discussed above to each SMA.
If that is not possible, then what would be the alternative to manipulating the SMA output so that it can effectively be used for UK price formatted stocks.
If you need any more information or clarification then don't hesitate to ask.