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:
PROC EXPAND OUT=OMXS30 METHOD=NONE;
CONVERT MATS=MA_OMXSKORT / TRANSFORM=(MOVAVE 50);
CONVERT MATS=MA_OMXSLANG / TRANSFORM=(MOVAVE 200);
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
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....).
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.