BookmarkSubscribeRSS Feed
Calcite | Level 5

Hi Guys!


New here and pretty new to SAS to be honest. Writing on a thesis where I want to test how MA50 and MA200 perform over years. The time period is 1997-01-01 to 2018-05-18. What I want to do in SAS is to create a code that automate buys and sells. To be more specific, in one code I want a program that compare the average price for the 50 latest day's and compare that with the price today. If the price today is higher than the average, then buy, if it is less, then sell. I only want buy's and sell's to be done if it cross the moving average. For example if I buy today, and then measure and compare the new moving average tomorrow to the price tomorrow and it is still higher, then I don't want a new buy order to be executed. My plan is to start with 10.000$ and then use all of the capital for every signal. So buy-buy or sell-sell wont be possible.


I also want the program to aggregate the return from this and present the total amount of revenue(or loss) that was captured during this 21 year long period.

Furthermore I want to compare this to a simple buy-and-hold strategy. At the end i plan to execute a t-test to measure the significance in the different results.


Right now I'm trying:



Where I get the Moving average for every day. So the next step is pretty much everything else hehe.


To get to the question,


First of all, is the program that I am requesting even possible to do in SAS?

If it is, can someone point me in the right direction? I have been reading a lot this last week but just cant get my head around how I possibly can automate buys and sells in the program and at the same time get the aggregated result.


Best regards, Fridein

Ammonite | Level 13

SAS can certainly calculate moving averages and generate buy/sell signals along the lines you describe. However, your big problem Is the one you've correctly identified - automating the trades. I don't think SAS is going to be able to do this directly but there are ways that SAS can trigger actions in other programs e.g. by shelling out to the operating system and executing another program. This is by no means uncommon and something I've programmed myself many times. Having said that whether or not this is possible is going to depend on the trading platform you're using and I would think their security would make this something that was extremely challenging (in fact I'd hope it would or I wouldn't put any of my money there....).



Calcite | Level 5

Alright, I guess I need to use a different approach. Thank you so much for the answer however! 🙂



Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.


Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2 in conversation