股票策略的选择(平均移动均线)

This project asks you to write a C program to implement stock trading
strategies and evaluate the performance of each strategy.
Before we start, let us get familiar with a concept.
N-day simple moving average (N-SMA): defined as the average
price of the past N day stock prices. In mathematical term, if the stock
price of day i is labeled as pi, then the N-day simple moving average of day
t is defined as
N − SMAt =
t−1 X i=t−N
pi
N
N − SMAt is a function of t. Therefore, we can plot it as a curve with
t as the x−axis.
N − SMAt gives a smoothed stock price curve. Short-term averages
respond quickly to changes in the price of the underlying stock, while longterm
averages are slow to react.
When the short term SMA curve crosses the long term SMA curve from
below, it signals a bullish trend is forming, which is treated as a buy signal.
When the short term SMA curve crosses the long term SMA curve from
above, it signals a bearish trend is forming, which is treated as a sell signal.
Your three buy signals are defined as: (B1) 5−SMA crosses 20−SMA
from below; (B2) 20−SMA crosses 50−SMA from below; (B3) 50−SMA
crosses 200 − SMA from below.
Your three sell signals are defined as: (S1) 5 − SMA crosses 20 − SMA
from above; (S2) 20−SMA crosses 50−SMA from above; (S3) 50−SMA
crosses 200 − SMA from above.
You buy/sell when buy/sell signals appear. The three trading strategies
we define are: B1S1, B2S2, and B3S3. We define the fourthth strategy, buy
and hold strategy (BH) as following: buy on the first day of investment and
hold through all the years to the last day, never sell.
With this document, you will also find a text file named intel.txt which
contains the adjusted daily closing prices of Intel Corp. from 7-9-1986 to
10-10-2007. Assume you started investing in Intel’s stock on 10-12-1987
with $10,000. Test your investment performance for each of the four trading
strategies for the time period from 10-12-1987 to 10-10-2007.
To simplify the calculation, we use the following assumptions:
1. Use each day’s closing price for buy and sell.
1
Computer Programming Language
2. On 10-12-1987, if the short tem SMA is above the long term SMA,
buy. Otherwise, wait until the buy signal appears.
3. When you buy, use all the fund you have; when you sell, sell all the
stocks you hold.
4. For simplicity, we allow fractional shares of stocks.
5. For simplicity, no trading fees and taxes.
The investment performance is measured by Compound Annual Growth
Rate, (CAGR). In our case, the investment lasted 20 years, CAGR r is
calculated by
(1 + r)20 =
The value of your investment on the last day
The value of your investment on the first day
Your program should output each strategy’s name and its CAGR to a
text file named Performance.txt .
If you have more time, you may want to explore other strategies, such
as B3S1. 

------------------------------------------------------------------------------------------------

用这么简单的选股方法来炒股只有做梦发财的人才会用这种方法,他的方法是纯技术性的,在实际操作中造成的后果只是很缓慢资金增长或所有资金长期被套,因为程序中没有给出止损点,如果按照B1、B2、B3所列条件选股,只有把中线时间列为一年左右的人才有可能采取,但是没有止损点的情况下,要卖出只能等下一波行情的到来了!
这是一家程序公司自己的想法,同时出题的人并不懂股票,或者说他没有经历过自己炒股等类似的事情。
大致翻译过来时这样的:
定义N-SMA为N天的移动平均值,相当于我们平时见到的5日均线、10日均线的定义。设定3个买入点:B1为5日均线从下方穿过20日均线,B2为20日均线从下方穿过50日均线,B3为50日均线从下方穿过200日均线。
又设定了3个卖出点:S1为5日均线从上方穿过20日均线,S2为20日均线从上方穿过50日均线,S3为50日均线从上方穿过200日均线.
这样定义了3种交易方法:B1S1, B2S2和B3S3,同时又定义了一种BH方法:买入原始股后永远持有。
具体程序用到的就是这么多了。然后你抄来题目的地方应该还有一个文件INTEL.TXT没有发上来,那里记录的是英特尔公司1986年7月9日至2007年10月10日的全部收盘价,利用4种交易方法计算1987年10月12日持有10000元操作到2007年10月10日的结果用来检验你的程序。
另外为简化模型,设定了5条:
1、交易使用每天的收盘价;
2、1987年10月12日如果短期均线在长期均线上方时买入,否则等待买入信号的出现;
3、每次交易使用最大量,即买入时投入所有现金,卖出时买出所有持有股票;
4、允许进行零星股份的交易;
5、不计入交易费用和交易税。
在以下是要以固定格式:(1+r)20=结果 计算最终日期 计算开始日期 记录到Performance.txt这个文件里。
最后是玩你一把:有时间的话可以用其他交易方法计算一遍比如B3S1。

-----------------------------------------------------------------------------------------------------------------------

移动平均线(Moving Average)
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值