Skip to content

Instantly share code, notes, and snippets.

@hsinjungwu
hsinjungwu / fn_CalBondDateFactor.sql
Last active March 13, 2017 19:07
Bond Valuation and Duration
CREATE FUNCTION fn_CalBondDateFactor(@code VARCHAR(40), @settlement smalldatetime, @opt smallint)
RETURNS @payDays TABLE(payIntDays INT, unPayIntDays INT, payIntPeriodDays INT)
BEGIN
--付息期間起迄日
DECLARE @startPeriodDate smalldatetime, @endPeriodDate smalldatetime
SELECT @startPeriodDate = startDay, @endPeriodDate = endDay
FROM fn_GetBondReturnInterval(@code)
WHERE @settlement BETWEEN startDay AND endDay
--判斷是否月底付息
@hsinjungwu
hsinjungwu / fn_cal_bond_prum.sql
Last active October 25, 2015 11:24
產生債券折溢價 TABLE,之後可直接查表
/*---------------------------------
@tradeno 交易單號
@opt : 0 直線法, 1 利息法
---------------------------------*/
CREATE FUNCTION fn_CalPrum(@tradeno varchar(40), @opt smallint)
RETURNS @discount TABLE (sday smalldatetime, eday smalldatetime, qty numeric(20,5), payint numeric(20,5), in_int numeric(20,5), out_int numeric(20,5), prum numeric(20,5), dailyPrum numeric(20,5), amount numeric(20,5))
BEGIN
DECLARE @r numeric(20,10), @y numeric(20,10), @code varchar(40), @qty numeric(20,5), @payint numeric(20,5), @amount numeric(20,5), @calDate smalldatetime
@hsinjungwu
hsinjungwu / SplitCsvLine.cs
Last active October 3, 2015 18:14
SplitCsvLine
private static List<string> SplitCsvLine(string line)
{
List<string> result = new List<string>();
string[] word = line.Split(',');
bool hasOddQuota = false;
for (int i = 0; i < word.Length; i++)
{
StringBuilder sb = new StringBuilder(word[i]);
do
@hsinjungwu
hsinjungwu / GetISINcode.cs
Last active August 29, 2015 14:21
ISIN code
public static string GetIsincode(string country, string cusip)
{
string s = (country + cusip).ToUpper();
StringBuilder sb = new StringBuilder();
foreach (char c in s)
{
if (c <= 'Z' && c >= 'A') sb.Append(((c - 'A') + 10).ToString());
else sb.Append(c.ToString());
}
@hsinjungwu
hsinjungwu / data_mask.sql
Last active August 29, 2015 14:21
add mask to data
DECLARE @name NVARCHAR(20) = N'王小明'
DECLARE @mask_name NVARCHAR(20)
SELECT @mask_name = STUFF(@name, 2, LEN(@name)-1, REPLICATE ('*' , LEN(@name)-1))
PRINT @mask_name
-- @mask_name = 王**
@hsinjungwu
hsinjungwu / FOR_XML_PATH.sql
Created January 15, 2015 09:06
An example to Concatenates Values of specified column Group By another column in SQL Server
--REFERENCE:http://stackoverflow.com/a/19348687
DECLARE @table TABLE(idx INT, name VARCHAR(10))
INSERT @table VALUES(0, 'hjwu01')
INSERT @table VALUES(0, 'hjwu02')
INSERT @table VALUES(0, 'hjwu03')
INSERT @table VALUES(1, 'hjwu11')
INSERT @table VALUES(1, 'hjwu12')
INSERT @table VALUES(2, 'hjwu21')
INSERT @table VALUES(2, 'hjwu22')
@hsinjungwu
hsinjungwu / EnumerateEnum.cs
Created November 10, 2014 10:21
c# Example
//ref : http://stackoverflow.com/a/105402
using System;
public class CSharpLab
{
public enum myColor
{
gray = 0,
grey = 0,
black,
@hsinjungwu
hsinjungwu / IntToChineseNumerals.cs
Last active August 29, 2015 14:08
Convert Integer To Words
using System;
using System.IO;
using System.Threading;
public class CSharpLab
{
public static void Test()
{
string[] chtInt = new string[]{"零","壹","貳","參","肆","伍","陸","柒","捌","玖"};
string[] moneyUnit1 = new string[] {"拾","佰","仟",};
@hsinjungwu
hsinjungwu / MERGE.sql
Last active August 29, 2015 14:08
SQL Example
DECLARE @candy TABLE (buydate SMALLDATETIME, name VARCHAR(10), piece INT)
INSERT @candy VALUES ('2014-09-01', 'candy1', 10)
INSERT @candy VALUES ('2014-09-01', 'candy2', 20)
INSERT @candy VALUES ('2014-10-01', 'candy2', 40)
INSERT @candy VALUES ('2014-10-01', 'candy3', 80)
DECLARE @delta TABLE (name VARCHAR(10), sep_count INT, oct_count INT)
INSERT @delta
SELECT name, piece, 0 FROM @candy WHERE buydate = '2014-09-01'
@hsinjungwu
hsinjungwu / ObfuscateByDotfuscator.cs
Last active August 29, 2015 14:04
example of obfuscate application
using System;
using System.ComponentModel;
using System.Drawing;
using System.Net;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace ftpTEST
{
public class Form1 : Form
{