407097: GYM102697 068 Relative Strength Index

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

068. Relative Strength Indextime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

When trading securities such as stocks and crypto-currencies in the markets, many traders look at mathematical tools called indicators. There are hundreds of different indicators for all sorts of purposes, but one of the most commonly used indicators is called the relative strength index, or RSI for short. The RSI provides an estimate of how the price of a security is likely to move, with a high RSI value(above 70) suggesting the item is overpriced and will decrease in value, while a lower value(below 30) suggests the opposite. The RSI is calculated with a simple formula that is based on the past prices of a security. This formula is given as: $$$100-(100/(RS+1))$$$ where $$$RS = aveUP/aveDOWN$$$. $$$aveUP$$$ is the average value among all of the times the price of the security increased between two measurements, and $$$aveDOWN$$$ is the average value among all of the times the price of the security decreased between two measurements. For this problem, take in the past $$$N$$$ prices of an asset, then determine the value of the RSI indicator. It is important to note that aveDOWN should be composed of the absolute value of each price decrease between two measurements, and therefore should have a positive value.

Input

The first line contains an integer $$$N$$$ representing the number of prices that will follow. The next line contains $$$N$$$ space-separated floating point values that correspond to each measurement of the price, with the first measurement being the first value provided.

Output

A single floating point value that represents the value of the RSI indicator for the given price history.

ExampleInput
4
6500.0 6510.0 6300.0 6200.0
Output
6.060606060606062
Note

Note that in real market RSI calculations, an exponential moving average(EMA) is used to process faster moving data, but you should use a simple moving average(SMA) to find the aveUP and aveDOWN values. A simple moving average is the same as finding the average value of a number set as you usually would. It is also very important to note that aveDOWN should include the absolute value of each decrease, and should therefore have a positive value. You can also assume that there will always be at least one price increase and at least one price decrease in the given data

加入题单

上一题 下一题 算法标签: