Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.86 KB | None | 0 0
  1. USE VanDam
  2.  
  3. IF object_id('IsSystematic', 'u') IS NOT NULL
  4. DROP TABLE IsSystematic
  5.  
  6. SELECT
  7. trAVAm.ExchProfile AS [ECN],
  8. MIN(EntryDate) AS [StartDate],
  9. MAX(EntryDate) AS [EndDate],
  10. COUNT(
  11. *) AS [Total Numbers of Trades],
  12. SUM(
  13. trAVAm.Volume) AS [Total Number of Shares Traded],
  14. trAVAm.LiqFlag,
  15. trAVAm.LiqInd,
  16. stats.Volume AS [Matched Volume],
  17. [Route Scheduled] AS [Real Rate Per Share for Flag],
  18. NULL AS [Lek Charges Per Share for Flag],
  19. SUM(trAVAm.Volume *
  20. [Route Scheduled]) AS [Real Charge $],
  21. SUM(
  22. [LEK Charged]) AS [Lek Charge $],
  23. -1 * Round(SUM(TotalDifference),
  24. 2) AS [Lek's Overcharge $ (Lek Charge - Real Charge)],
  25. NULL AS [Link To Official Exchange Document Re Charging],
  26. FullName AS [Notes],
  27. AVG(
  28. AvalonVolume) AS [AVG AvalonVolume],
  29. AVG(CADV) AS [AVG CADV],
  30. (SUM(Indicators.[Added Displayed Volume]) + SUM(Indicators.[Added Non-Displayed Volume])) /
  31. SUM(TCV_data.CADV) AS [AVG ADAV as percent],
  32. -- AVG([ADRV as percent]) AS [AVG ADRV as percent],
  33. AVG(
  34. [AddedVolume]) AS [AVG AddedVolume]
  35. INTO IsSystematic
  36. FROM (
  37. SELECT *
  38. FROM trAVAm_extended_20161025
  39. WHERE LiqFlag IS NOT NULL AND TotalDifference IS NOT NULL AND TotalDifference < 0) AS [trAVAm]
  40. LEFT JOIN RM_TierCodes AS [TierCodes]
  41. ON TierCodes.Route = trAVAm.Route
  42. AND TierCodes.ExchProfile = trAVAm.ExchProfile
  43. AND TierCodes.TierCode = trAVAm.Tier
  44. LEFT JOIN Indicators_new AS [Indicators]
  45. ON MONTH(trAVAm.EntryDate) = Month(Month)
  46. AND YEAR(EntryDate) = YEAR(Month)
  47. AND Indicators.Route = trAVAm.Route
  48. AND Indicators.ExchProfile = trAVAm.ExchProfile
  49. LEFT JOIN TCV AS [TCV_data]
  50. ON Month(Indicators.Month) = TCV_data.Month
  51. AND Year(Indicators.Month) = TCV_data.Year
  52. LEFT JOIN (
  53. SELECT DISTINCT
  54. [ExchProfile],
  55. [LiqInd],
  56. [LiqFlag],
  57. [Volume]
  58. FROM [VanDam].[dbo].[ProvedMathcing_with_stats]) AS stats
  59. ON trAVAm.ExchProfile = stats.ExchProfile
  60. -- AND LiqFlag = stats.LiqFlag
  61. AND trAVAm.LiqInd = stats.LiqInd
  62.  
  63.  
  64. WHERE trAVAm.LiqFlag IS NOT NULL AND TotalDifference IS NOT NULL AND trAVAm.TotalDifference < 0
  65. GROUP BY trAVAm.ExchProfile, trAVAm.LiqFlag, trAVAm.LiqInd, [Route Scheduled], FullName, stats.Volume
  66.  
  67.  
  68. SELECT *
  69. FROM IsSystematic
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement