For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Need help getting started, trying to graph draw down



  • I have tried to write a couple programs but haven't really been able to fully grasp how all the pieces fit together. I have tried reading a lot of the documentation and examples online etc... But I quickly get lost... It seems they start with super simple examples but quickly get complicated. Also, I see lots of little differences with how they go about programming something that is basically the same thing. I understand there are lots of ways to skin a cat... But this causes me to just get confused. As far as I am concerned, I don't really care at this point what the "best" way is. Even the "worst" way is better than "no" way at this point which is where I am currently at.

    I am trying to keep things simple to start, as I learn and progress, I can "improve" and learn why I should do things one way vs the other.

    Ok... So I simply want to make a graph of the "drawdown" for Tesla. At this point, I would like to simply hard code "Tesla" and if i want to see drawdown for apple... Then I can backspace a couple times and type in Apple.

    As I understand, I may need to place an order to actually produce a graph of drawdown. If this is the case then I would like to simply say I buy 1 share on X date. For example, I buy 1 share on July 2nd, 2019. Then If I want to change the date... I can simply backspace a few times and type in a new date.

    One problem I keep running into is that I find only a piece of the code I need. For example just the piece to show drawdown but I can't never figure out how to add it to my code.

    Here is what I have been able to successfully accomplish. Which I am really proud of although it took me a ridiculous number of hours to get this far. Many of the examples use data from a file, I like that this can pull some of the latest data from online by simply changing the dates.

    from __future__ import (absolute_import, division, print_function, unicode_literals)
    
    from datetime import datetime
    
    import backtrader as bt
    
    # Create a cerebro enity (cerebro engine)
    cerebro = bt.Cerebro()
    
    # Get TSLA data
    # ** Easy to change Tesla to another stock like Apple
    # **** Just backspace and enter new ticker symbol and hit run
    # ** Easy to change Date
    # **** Just backspace and enter new date and hit run
    data = bt.feeds.YahooFinanceData(dataname='TSLA', fromdate=datetime(2019, 1, 1), todate=datetime(2019, 12, 31))
    
    # Add TSLA data to cerebro engine (inject a datafeed)
    cerebro.adddata(data)
    
    # Run over everything
    cerebro.run()
    
    # Plot TSLA data
    cerebro.plot()
    

    Can someone please help me to add drawdown to this? I know if someone provided the solution, I could study it and begin to understand how all this works. Again, keep it simple for me, just the basic minimum I need to add a plot of drawdown to the code above. Thank you.


Log in to reply
 

});