编程介的小学生 2017-03-25 16:49 采纳率: 20.5%
浏览 817
已采纳

Easy Trading

Frank is a professional stock trader for Advanced Commercial Markets Limited (ACM Ltd ). He likes "easy trading" --- using a straightforward strategy to decide when to buy stock and when to sell it.

Frank has a database of historical stock prices for each day. He uses two integer numbers m and n (1 ≤ m < n ≤ 100) as parameters of his trading strategy. Every day he computes two numbers: P (m) --- an average stock price for the previous m days, and P (n) --- an average stock price for the previous n days. P (m) > P (n) is an indicator of the upward trend (traders call it bullish trend), and P (m) < P (n) is an indicator of the downward trend (traders call it bearish trend). In practice the values for P (m) and P (n) are never equal.

When a trend reverses from bearish to bullish it is a signal for Frank to buy stock. When a trend reverses from bullish to bearish it is a signal to sell.

Frank has different values for m and n in mind and he wants to backtest them using historical prices. He takes a set of k (n < k ≤ 10 000) historical prices pi (0 < pi < 100 for 1 ≤ i ≤ k). For each i (n ≤ i ≤ k) he computes pi (m) and pi (n) --- an arithmetic average of pi-m+1 . . . pi and pi-n+1 . . . pi respectively.

Backtesting generates trading signals according to the following rules.

. If pi (m) > pi (n) there is a bullish trend for day i and a "BUY ON DAY i" signal is generated if i = n or there was a bearish trend on day i - 1.

. If pi (m) < pi (n) there is a bearish tread for day i and a "SELL ON DAY i" signal is generated if i = n or there was a bullish trend on day i - 1.

Your task is to write a program that backtests a specified strategy for Frank --- you shall print a signal for the first tested day (day n) followed by the signals in increasing day numbers.

Input

There are several test cases in the input. The first line of each case contains three integer numbers m, n, and k. It is followed by k lines with stock prices for days 1 to k. Each stock price pi is specified with two digits after decimal point. Prices in the input file are such that pi (m) ≠ pi (n) for all i (n ≤ i ≤ k).

Output

Write to the output file a list of signals --- one signal on a line, as described in the problem statement.

Sample Input

3 5 17
8.45
9.10
9.40
10.15
10.40
11.08
11.52
12.12
12.51
12.15
11.90
11.25
11.73
10.77
10.80
10.01
9.14
Sample Output

BUY ON DAY 5
SELL ON DAY 12

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-04-03 15:33
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算