- Send SMS alerts from your trading algorithms in Pythonby JeremyWhittaker
Occasionally there may be some important alerts that you want your trading algorithms to send to you that require immediate attention. One that I use frequently is daily account drawdown. Here’s how you can set up Twilio to send you a text message when your account enters a certain percentage of drawdown.
Head over to Twilio
You do need to purchase a number to text from. It costs $1/month. You can find that here.
You’ll now need to go to your general settings page to retrieve your live credentials.
The next step is to install Twilio on your operating system. I use Ubuntu this can be done with the following command
sudo pip3 install twilio
Great now you’re ready to code.
The first thing you want to do is write a simple Python script to test your message sending capabilities. In the below code you’ll want to change a few variables:
account_sid – Change with your Twilio information found on your account page.
Auth_token – Change with your Twilio information found on your account page.
Using the format +19998887777 change to_num to your cell
Using the format +19998887777 change from_num to your Twilio phone number
def send_sms(to_num,from_num,body_message): import os from twilio.rest import Client account_sid = 'Enter your account sid here' auth_token = 'Enter your account token here' client = Client(account_sid, auth_token) try: message = client.messages.create( to=to_num, from_=from_num, body=body_message ) print(message.sid) except Exception as e: print(e) if __name__ == '__main__': send_sms(+14809999999,+17149999999,'test')
Now that we have a function that can send text messages we just need to incorporate this into our code.
- Setting up Python algos to run on Ubuntu startup using systemdby JeremyWhittaker
If you’re running your trading algorithms on Linux the best way to get them to start on bootup is to use a service called systems. Here are the steps on setting that up.
Then create a new service as root:
sudo nano trading_algo_23.service
Here is a sample of what the file should look like. You can find your account name by using the command whoami in linux
[Unit] Description=This algo is designed to hedge... User=your username WorkingDirectory=/directory/of/algo ExecStart=/usr/bin/python3 /directory/of/algo/algo_23.py Restart=always [Install] WantedBy=multi-user.target
Now reload systems
sudo systemctl daemon-reload
Enable the service
sudo systemctl enable
Start your script:
sudo systemctl start trading_algo_23.service
Check the status:
sudo systemctl status trading_algo_23.service
- Setting up Python algos to run on Ubuntu startup using crontabby JeremyWhittaker
If you’re using Ubuntu or some other flavor of Linux you more than likely want your algorithm to start with the server. This is a pretty straightforward process.
The first thing you’ll want to do is make sure cron is installed
sudo apt-get update sudo apt-get install cron
Next run crontab -e select nano when it asks which editor. The code below can be used as a template The first two lines are just writing the current date to the log files on reboot so you know when the server was restarted.
@reboot date >> /home/me_jeremywhittaker_com/AAII/log.txt @reboot date >> /home/me_jeremywhittaker_com/AAII/errors.txt
I actually am running two scripts for this particular strategy. Each one gets its own line of code. This basically tells it to run on on startup @reboot then the path to the script to execute,
@reboot /home/me_jeremywhittaker_com/queen_of_stonks/queen_of_stonks_monitor.py >> /home/me_jeremywhittaker_com/queen_of_stonks/logs.txt 2>> /home/me_jeremywhittaker_com/queen_of_stonks/errors.txt @reboot /home/me_jeremywhittaker_com/queen_of_stonks/queen_of_stonks_trade.py >> /home/me_jeremywhittaker_com/queen_of_stonks/logs.txt 2>> /home/me_jeremywhittaker_com/queen_of_stonks/errors.txt
That’s it. We can now do a sudo reboot and our scripts should start with our server and save to the log files indicated.
- Earn 7.12% on money sitting in your checking or savings account and hedge against inflation, risk-free, here’s how.by JeremyWhittaker
If you’re like me you probably have money sitting in your checking, savings, or money-market account. Paying practically zero interest and getting eaten alive by inflation. Here’s what you can do to earn 7.12% on that money and get inflation-adjusted returns on your excess cash.
Yield on savings and checking accounts are horrible
If you’re like me you’re probably trying to move your liquid funds around into these high-yield savings accounts which aren’t exactly keeping up with inflation. In fact, to date, the highest I can find is LendingClub at 0.60%
Inflation is a regressive tax on the poor and middle class
The annual inflation rate in the US has surged to 6.2% in October to 2021 according to the US Bureau of Labor and Statistics. This means your buying power is dropping significantly if you are holding on to cash. You of course know this if you have bought anything recently.
Use I bonds for risk-free inflation-adjusted return on your cash
To get the 7.12% yield you can buy I bonds which are backed by the United States government. They are inflation-adjusted. Meaning, you’re not technically building any wealth but you’re also not allowing the government to steal it through inflation. You can read more about how the rate is calculated here.
- I bonds are an excellent investment rather than holding cash
- They are exempt from state and local taxes
- Subject to federal taxes.
- Tax-deferred until you redeem them.
- Mature in 30-years or until you redeem them
- Redeemable after the first year of purchase
- Early redemption is penalized with 3-months worth of interest
- Interest is compounded every 6-months
- Your money is locked up for a duration of 1-year
Historical I bond rates
Period when you bought
your I bond
Composite rate for your six-month earning period starting during November 2021 – April 2022
(See “When does my bond change rates?”)
From Through Nov. 2021 Apr. 2022 7.12% May 2021 Oct. 2021 7.12% Nov. 2020 Apr. 2021 7.12% May 2020 Oct. 2020 7.12% Nov. 2019 Apr. 2020 7.33% May 2019 Oct. 2019 7.64% Nov. 2018 Apr. 2019 7.64% May 2018 Oct. 2018 7.43% Nov. 2017 Apr. 2018 7.22% May 2017 Oct. 2017 7.12% Nov. 2016 Apr. 2017 7.12% May 2016 Oct. 2016 7.22% Nov. 2015 Apr. 2016 7.22% May 2015 Oct. 2015 7.12% Nov. 2014 Apr. 2015 7.12% May 2014 Oct. 2014 7.22% Nov. 2013 Apr. 2014 7.33% May 2013 Oct. 2013 7.12% Nov. 2012 Apr. 2013 7.12% May 2012 Oct. 2012 7.12% Nov. 2011 Apr. 2012 7.12% May 2011 Oct. 2011 7.12% Nov. 2010 Apr. 2011 7.12% May 2010 Oct. 2010 7.33% Nov. 2009 Apr. 2010 7.43% May 2009 Oct. 2009 7.22% Nov. 2008 Apr. 2009 7.84% May 2008 Oct. 2008 7.12% Nov. 2007 Apr. 2008 8.36% May 2007 Oct. 2007 8.47% Nov. 2006 Apr. 2007 8.57% May 2006 Oct. 2006 8.57% Nov. 2005 Apr. 2006 8.16% May 2005 Oct. 2005 8.36% Nov. 2004 Apr. 2005 8.16% May 2004 Oct. 2004 8.16% Nov. 2003 Apr. 2004 8.26% May 2003 Oct. 2003 8.26% Nov. 2002 Apr. 2003 8.78% May 2002 Oct. 2002 9.19% Nov. 2001 Apr. 2002 9.19% May 2001 Oct. 2001 10.23% Nov. 2000 Apr. 2001 10.64% May 2000 Oct. 2000 10.85% Nov. 1999 Apr. 2000 10.64% May 1999 Oct. 1999 10.54% Nov. 1998 Apr. 1999 10.54% Sept. 1998 Oct. 1998 10.64%
Here’s how you can buy I bonds
The first step is to sign up for a TreasuryDirect account which can be done here.
Once your account is set up you can log in here. You should have received your account number via email confirmation.
Once logged in you’ll see this screen.
Click on the BuyDirect option at the top. You’ll want to select series I bonds.
The most you can buy per social security number is $10,000/year
That’s it. Click submit.
And finally your confirmation page. Pretty simple and straightforward process.
If you have kids you can gift $10,000/year to them as well in I bonds. Read more on gifting I bonds here.
Want to purchase $5,000 more in I bonds every year?
You are also allowed to buy an additional $5,000 worth of I bonds every year with your tax return. That is of course if you have a tax return. You can do this by overpaying your taxes intentionally to the IRS via their website, here. I wouldn’t overpay by exactly $5,000 but probably an amount over. You can read more of the details on that process here. They are going to send you paper I bonds so you will want to convert them and attach them to your online account for ease of management. You buy I bonds with your tax return by submitting tax form 8888 with your taxes
Converting your I bonds to treasury direct electronic format
Directions on this process can be found on the treasury direct website, here.
You will need to create a conversion account one time.
You then need to create a registration list that matches the paper bond ownership that is printed on the paper bonds.
- Used car as an investment?by JeremyWhittaker
With inflation running rampant you could actually justify the purchase of a used car as an investment… Crazy when you think about it.
Facebook Comments Box