Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

Creating Bollinger Bands with SQL Server Reporting Service reports

$
0
0

One of the most powerful reporting tools is Microsoft is SQL Server Reporting Service, also known as SSRS. SSRS offers various, impressive features including reports subscriptions, custom code, paginated reports etc. In this article, we are going to review some key features in SSRS, with a highlight on Bollinger Bands

Calculated series

A little-known feature known as a calculated series is very handy for financial and statistical analysis when working with SSRS. Calculated series lets us add statistical analyses to SQL Server Reporting Service report charts. The advantage of this calculated series is that we don’t need to create any complex expressions or calculations. We can add this statistical analysis to SSRS reports very easily.

You can find these calculated series in SSRS

Mean Median Bollinger bands Moving average Exponential moving average Triangular moving average Weighted moving average MACD De trended price oscillator Envelopes Performance Rate of change Relative strength index Standard deviation TRIX

After this, calculated series shield SSRS charts are more useful because these type of charts do not only illustrate data, because statistical methods convert pure data into more meaningful than before and let us make estimations.

The intent of this article is to highlight how to create a calculated series in SSRS reports and usage details. Because this feature can be useful in advanced analyses, for example, you can find several types of moving average calculations and these methods can help to determine the trend of a data series.

Bollinger Bands

As client requirements increase day by day and they want to see more and more details in their reports. Especially in the financial trading and investing ecosystem, traders and investors need to make proper decisions in a timely manner and they require statistics reports to take these decisions. In this article, we will mention about Bollinger Bands technique and how to apply this method in Reporting Service reports.

In financial market analysis, the Bollinger Band method has very common usage. Bollinger Bands were first used by the famous analyst and trader by John Bollinger in 1980. This technique is designed to measure price changes in the market. The essential usage of Bollinger Bands include estimating the future price of the investment instrument, seeing the market volatilities and assisting in determining buy and sell signals. The Bollinger Band technique can determine

the investment instrument direction of the trend the price movements of volatility top and bottom levels of price the price targets

When we look at the Bollinger Bands calculation details; it uses two main statistical methods, one of which is a standard deviation and the other one is moving average. Standard deviation is a statistical formula which measures volatility . Bollinger Bands measure price volatility and adjust themselves to market conditions. Bollinger Bands include three different curves; lower, center and upper. The center curve is based on a 20-day simple moving average. The lower and upper bands are formed by shifting the 20-day moving average by 2 standard deviation values in the up and down direction.

Calculation Formula of Bollinger Bands:

Center Bollinger Band: 20 days of moving average

Lower Bollinger Band: 20 days of moving average (2 x 20 days standard deviation)

Upper Bollinger Band: 20 days of moving average + (2 x 20 days standard deviation)


Creating Bollinger Bands with SQL Server Reporting Service reports
How to create Bollinger Bands on SQL Server Reporting Services reports charts

After this brief introduction about Bollinger Bands, we can focus how to create calculated series of Bollinger Bands in SQL Server Reporting Service reports. First of all; we need a dataset like this because this structure of data is the default for financial analyses.


Creating Bollinger Bands with SQL Server Reporting Service reports

The following SQL script enables to create synthetic demo data or you can import this data from any financial websites to SQL Server.

DROP TABLE IF EXISTS BollingerBandSample CREATE TABLE BollingerBandSample ([OPEN]FLOAT, HIGHFLOAT, LOWFLOAT, [CLOSE]FLOAT, VOLUMEFLOAT, [DATE]DATETIME) DECLARE @J AS INT=0 DECLARE @Dt AS DATETIME ='20120101' WHILE @J<=100 BEGIN SET @J= @J+1 INSERT INTO BollingerBandSample ([OPEN],HIGH,LOW,[CLOSE],VOLUME,[DATE]) VALUES(round(RAND()*1,2) + 167,round(RAND()*1,2) + 168,round(RAND()*1,2) + 167,round(RAND()*1,2) + 167,TRY_CAST(RAND()*10000 AS INT) ,DATEADD(DAY,@J*+1,@Dt)) END SELECT * FROM BollingerBandSample

In this step, we will create a SQL Server Reporting Service report with Microsoft SQL Server Report Builder .

We will open a blank report.


Creating Bollinger Bands with SQL Server Reporting Service reports

Right click Data Sources and click Add Data Source


Creating Bollinger Bands with SQL Server Reporting Service reports

Chose Use a connection embedded in my report and define SQL Server connection settings.


Creating Bollinger Bands with SQL Server Reporting Service reports

Right click datasets and click Add Dataset


Creating Bollinger Bands with SQL Server Reporting Service reports

Chose Use a dataset embedded in my report and select data source which created the previous step. Select Query type as text and paste the query.


Creating Bollinger Bands with SQL Server Reporting Service reports

Click Insert Chart and select line chart.


Creating Bollinger Bands with SQL Server Reporting Service reports
Creating Bollinger Bands with SQL Server Reporting Service reports

Set the Values and Category Groups fields like this.


Creating Bollinger Bands with SQL Server Reporting Service reports

Right click the Vertical Axis Properties and change the axis maximum and minimum range values with these expressions.


Creating Bollinger Bands with SQL Server Reporting Service reports
Creating Bollinger Bands with SQL Server Reporting Service reports

After completing all these steps; we will run the report and our report will look like this.


Creating Bollinger Bands with SQL Server Reporting Service reports

And we will return design panel and add Bollinger Bands to this chart. Right click on the chart design and select Add Calculated Series.


Creating Bollinger Bands with SQL Server Reporting Service reports

Select Bollinger bands.


Creating Bollinger Bands with SQL Server Reporting Service reports

In this step we have to set two parameters. These parameters directly affect the Bollinger Bands calculation.

Periodparameter defines the day number of moving average period. We will set this parameter 20 as in general usage.

No of std. devastationsparameter can be defined as standard deviation multiplier or coefficient in the upper and lower bands. When we increase this parameter there will be more data between the upper and lower band. In the standard formula of Bollinger this parameter is 2 and we will also s

Viewing all articles
Browse latest Browse all 3160

Trending Articles